/**
 * 
 */
package t4j.typeinfo.toys;

/**
 * @author sz
 *
 * create time：2012-12-12
 */

interface HasBatteries{}

interface Waterproof{}

interface Shoots{}

class Toy{
	Toy(){}
	Toy(int i ){}
}

class FancyToy extends Toy implements HasBatteries,Waterproof,Shoots{
	FancyToy(){super(1);}
}

public class ToyTest {

	static void printInfo(Class cc){
		System.out.println("Class name: " + cc.getName() + " is interface? [" + cc.isInterface() + "]");//是否接口
		
		System.out.println("Simple name: " + cc.getSimpleName());//获取类名
		
		System.out.println("Canonical name: " + cc.getCanonicalName());//获取完整的类名
	}
	
	public static void main(String[] args) {
		Class c = null;
		
		try {
			c = Class.forName("t4j.typeinfo.toys.FancyToy");//创建
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			
			System.exit(1);
		}
		
		printInfo(c);
		
		for(Class face : c.getInterfaces())//获取当前类实现的接口，并循环
			printInfo(face);
		
		Class up = c.getSuperclass();//获取当前类的父类
		
		Object obj = null;
		
		 try {
			obj = up.newInstance();//创建父类实例
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();System.exit(1);
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();System.exit(1);
		}
		
		printInfo(obj.getClass());
	}
}
